package com.black.common.mybatis;

import com.black.common.mybatis.datascope.DataScopeHandlerInterceptorRegistry;
import com.black.common.mybatis.datascope.MyDataScopeSqlHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;

/**
 * @author linwenfeng
 */
@Configuration
@AutoConfigureBefore({MybatisPlusConfig.class})
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class MyDataScopeConfig {


    private final DataScopeHandlerInterceptorRegistry scopeHandlerInterceptorRegistry;

    @Bean
    public MyDataScopeSqlHandler myDataScopeSqlHandler() {
        return new MyDataScopeSqlHandler();
    }

    @PostConstruct
    public void registryDataScopeSqlHandler() {
        scopeHandlerInterceptorRegistry.addInterceptor(myDataScopeSqlHandler());
    }
}
